home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / modes / icon.el < prev    next >
Encoding:
Text File  |  1995-03-25  |  19.8 KB  |  554 lines

  1. ;;; icon.el --- mode for editing Icon code
  2. ;; Keywords: languages
  3.  
  4. ;; Note: use
  5. ;;  (autoload 'icon-mode "icon" nil t)
  6. ;;  (setq auto-mode-alist (cons '("\\.icn$" . icon-mode) auto-mode-alist))
  7. ;; if not permanently installed in your emacs
  8.  
  9. ;; Icon code editing commands for Emacs
  10. ;; Derived from c-mode.el  15-Feb-89  Chris Smith  convex!csmith
  11. ;; Copyright (C) 1989 Free Software Foundation, Inc.
  12.  
  13. ;; This file is part of XEmacs.
  14.  
  15. ;; XEmacs is free software; you can redistribute it and/or modify it
  16. ;; under the terms of the GNU General Public License as published by
  17. ;; the Free Software Foundation; either version 2, or (at your option)
  18. ;; any later version.
  19.  
  20. ;; XEmacs is distributed in the hope that it will be useful, but
  21. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  22. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23. ;; General Public License for more details.
  24.  
  25. ;; You should have received a copy of the GNU General Public License
  26. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  27. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  
  29.  
  30. (defvar icon-mode-abbrev-table nil
  31.   "Abbrev table in use in Icon-mode buffers.")
  32. (define-abbrev-table 'icon-mode-abbrev-table ())
  33.  
  34. (defvar icon-mode-map ()
  35.   "Keymap used in Icon mode.")
  36. (if icon-mode-map
  37.     ()
  38.   (setq icon-mode-map (make-sparse-keymap))
  39.   (define-key icon-mode-map "{" 'electric-icon-brace)
  40.   (define-key icon-mode-map "}" 'electric-icon-brace)
  41.   (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
  42.   (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
  43.   (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
  44.   (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
  45.   (define-key icon-mode-map "\177" 'backward-delete-char-untabify)
  46.   (define-key icon-mode-map "\t" 'icon-indent-command))
  47.  
  48. (defvar icon-mode-syntax-table nil
  49.   "Syntax table in use in Icon-mode buffers.")
  50.  
  51. (if icon-mode-syntax-table
  52.     ()
  53.   (setq icon-mode-syntax-table (make-syntax-table))
  54.   (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
  55.   (modify-syntax-entry ?# "<" icon-mode-syntax-table)
  56.   (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
  57.   (modify-syntax-entry ?$ "." icon-mode-syntax-table)
  58.   (modify-syntax-entry ?/ "." icon-mode-syntax-table)
  59.   (modify-syntax-entry ?* "." icon-mode-syntax-table)
  60.   (modify-syntax-entry ?+ "." icon-mode-syntax-table)
  61.   (modify-syntax-entry ?- "." icon-mode-syntax-table)
  62.   (modify-syntax-entry ?= "." icon-mode-syntax-table)
  63.   (modify-syntax-entry ?% "." icon-mode-syntax-table)
  64.   (modify-syntax-entry ?< "." icon-mode-syntax-table)
  65.   (modify-syntax-entry ?> "." icon-mode-syntax-table)
  66.   (modify-syntax-entry ?& "." icon-mode-syntax-table)
  67.   (modify-syntax-entry ?| "." icon-mode-syntax-table)
  68.   (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
  69.  
  70. (defconst icon-indent-level 4
  71.   "*Indentation of Icon statements with respect to containing block.")
  72. (defconst icon-brace-imaginary-offset 0
  73.   "*Imagined indentation of a Icon open brace that actually follows a statement.")
  74. (defconst icon-brace-offset 0
  75.   "*Extra indentation for braces, compared with other text in same context.")
  76. (defconst icon-continued-statement-offset 4
  77.   "*Extra indent for lines not starting new statements.")
  78. (defconst icon-continued-brace-offset 0
  79.   "*Extra indent for substatements that start with open-braces.
  80. This is in addition to icon-continued-statement-offset.")
  81.  
  82. (defconst icon-auto-newline nil
  83.   "*Non-nil means automatically newline before and after braces
  84. inserted in Icon code.")
  85.  
  86. (defconst icon-tab-always-indent t
  87.   "*Non-nil means TAB in Icon mode should always reindent the current line,
  88. regardless of where in the line point is when the TAB command is used.")
  89.  
  90. (defun icon-mode ()
  91.   "Major mode for editing Icon code.
  92. Expression and list commands understand all Icon brackets.
  93. Tab indents for Icon code.
  94. Paragraphs are separated by blank lines only.
  95. Delete converts tabs to spaces as it moves back.
  96. \\{icon-mode-map}
  97. Variables controlling indentation style:
  98.  icon-tab-always-indent
  99.     Non-nil means TAB in Icon mode should always reindent the current line,
  100.     regardless of where in the line point is when the TAB command is used.
  101.  icon-auto-newline
  102.     Non-nil means automatically newline before and after braces
  103.     inserted in Icon code.
  104.  icon-indent-level
  105.     Indentation of Icon statements within surrounding block.
  106.     The surrounding block's indentation is the indentation
  107.     of the line on which the open-brace appears.
  108.  icon-continued-statement-offset
  109.     Extra indentation given to a substatement, such as the
  110.     then-clause of an if or body of a while.
  111.  icon-continued-brace-offset
  112.     Extra indentation given to a brace that starts a substatement.
  113.     This is in addition to icon-continued-statement-offset.
  114.  icon-brace-offset
  115.     Extra indentation for line if it starts with an open brace.
  116.  icon-brace-imaginary-offset
  117.     An open brace following other text is treated as if it were
  118.     this far to the right of the start of its line.
  119.  
  120. Turning on Icon mode calls the value of the variable icon-mode-hook with no args,
  121. if that value is non-nil."
  122.   (interactive)
  123.   (kill-all-local-variables)
  124.   (use-local-map icon-mode-map)
  125.   (setq major-mode 'icon-mode)
  126.   (setq mode-name "Icon")
  127.   (setq local-abbrev-table icon-mode-abbrev-table)
  128.   (set-syntax-table icon-mode-syntax-table)
  129.   (make-local-variable 'paragraph-start)
  130.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  131.   (make-local-variable 'paragraph-separate)
  132.   (setq paragraph-separate paragraph-start)
  133.   (make-local-variable 'indent-line-function)
  134.   (setq indent-line-function 'icon-indent-line)
  135.   (make-local-variable 'require-final-newline)
  136.   (setq require-final-newline t)
  137.   (make-local-variable 'comment-start)
  138.   (setq comment-start "# ")
  139.   (make-local-variable 'comment-end)
  140.   (setq comment-end "")
  141.   (make-local-variable 'comment-column)
  142.   (setq comment-column 32)
  143.   (make-local-variable 'comment-start-skip)
  144.   (setq comment-start-skip "# *")
  145.   (make-local-variable 'comment-indent-hook)
  146.   (setq comment-indent-hook 'icon-comment-indent)
  147.   (run-hooks 'icon-mode-hook))
  148.  
  149. ;; This is used by indent-for-comment
  150. ;; to decide how much to indent a comment in Icon code
  151. ;; based on its context.
  152. (defun icon-comment-indent ()
  153.   (if (looking-at "^#")
  154.       0    
  155.     (save-excursion
  156.       (skip-chars-backward " \t")
  157.       (max (if (bolp) 0 (1+ (current-column)))
  158.        comment-column))))
  159.  
  160. (defun electric-icon-brace (arg)
  161.   "Insert character and correct line's indentation."
  162.   (interactive "P")
  163.   (let (insertpos)
  164.     (if (and (not arg)
  165.          (eolp)
  166.          (or (save-excursion
  167.            (skip-chars-backward " \t")
  168.            (bolp))
  169.          (if icon-auto-newline
  170.              (progn (icon-indent-line) (newline) t)
  171.            nil)))
  172.     (progn
  173.       (insert last-command-char)
  174.       (icon-indent-line)
  175.       (if icon-auto-newline
  176.           (progn
  177.         (newline)
  178.         ;; (newline) may have done auto-fill
  179.         (setq insertpos (- (point) 2))
  180.         (icon-indent-line)))
  181.       (save-excursion
  182.         (if insertpos (goto-char (1+ insertpos)))
  183.         (delete-char -1))))
  184.     (if insertpos
  185.     (save-excursion
  186.       (goto-char insertpos)
  187.       (self-insert-command (prefix-numeric-value arg)))
  188.       (self-insert-command (prefix-numeric-value arg)))))
  189.  
  190. (defun icon-indent-command (&optional whole-exp)
  191.   (interactive "P")
  192.   "Indent current line as Icon code, or in some cases insert a tab character.
  193. If icon-tab-always-indent is non-nil (the default), always indent current line.
  194. Otherwise, indent the current line only if point is at the left margin
  195. or in the line's indentation; otherwise insert a tab.
  196.  
  197. A numeric argument, regardless of its value,
  198. means indent rigidly all the lines of the expression starting after point
  199. so that this line becomes properly indented.
  200. The relative indentation among the lines of the expression are preserved."
  201.   (if whole-exp
  202.       ;; If arg, always indent this line as Icon
  203.       ;; and shift remaining lines of expression the same amount.
  204.       (let ((shift-amt (icon-indent-line))
  205.         beg end)
  206.     (save-excursion
  207.       (if icon-tab-always-indent
  208.           (beginning-of-line))
  209.       (setq beg (point))
  210.       (forward-sexp 1)
  211.       (setq end (point))
  212.       (goto-char beg)
  213.       (forward-line 1)
  214.       (setq beg (point)))
  215.     (if (> end beg)
  216.         (indent-code-rigidly beg end shift-amt "#")))
  217.     (if (and (not icon-tab-always-indent)
  218.          (save-excursion
  219.            (skip-chars-backward " \t")
  220.            (not (bolp))))
  221.     (insert-tab)
  222.       (icon-indent-line))))
  223.  
  224. (defun icon-indent-line ()
  225.   "Indent current line as Icon code.
  226. Return the amount the indentation changed by."
  227.   (let ((indent (calculate-icon-indent nil))
  228.     beg shift-amt
  229.     (case-fold-search nil)
  230.     (pos (- (point-max) (point))))
  231.     (beginning-of-line)
  232.     (setq beg (point))
  233.     (cond ((eq indent nil)
  234.        (setq indent (current-indentation)))
  235.       ((eq indent t)
  236.        (setq indent (calculate-icon-indent-within-comment)))
  237.       ((looking-at "[ \t]*#")
  238.        (setq indent 0))
  239.       (t
  240.        (skip-chars-forward " \t")
  241.        (if (listp indent) (setq indent (car indent)))
  242.        (cond ((and (looking-at "else\\b")
  243.                (not (looking-at "else\\s_")))
  244.           (setq indent (save-excursion
  245.                  (icon-backward-to-start-of-if)
  246.                  (current-indentation))))
  247.          ((or (= (following-char) ?})
  248.               (looking-at "end\\b"))
  249.           (setq indent (- indent icon-indent-level)))
  250.          ((= (following-char) ?{)
  251.           (setq indent (+ indent icon-brace-offset))))))
  252.     (skip-chars-forward " \t")
  253.     (setq shift-amt (- indent (current-column)))
  254.     (if (zerop shift-amt)
  255.     (if (> (- (point-max) pos) (point))
  256.         (goto-char (- (point-max) pos)))
  257.       (delete-region beg (point))
  258.       (indent-to indent)
  259.       ;; If initial point was within line's indentation,
  260.       ;; position after the indentation.  Else stay at same point in text.
  261.       (if (> (- (point-max) pos) (point))
  262.       (goto-char (- (point-max) pos))))
  263.     shift-amt))
  264.  
  265. (defun calculate-icon-indent (&optional parse-start)
  266.   "Return appropriate indentation for current line as Icon code.
  267. In usual case returns an integer: the column to indent to.
  268. Returns nil if line starts inside a string, t if in a comment."
  269.   (save-excursion
  270.     (beginning-of-line)
  271.     (let ((indent-point (point))
  272.       (case-fold-search nil)
  273.       state
  274.       containing-sexp
  275.       toplevel)
  276.       (if parse-start
  277.       (goto-char parse-start)
  278.     (setq toplevel (beginning-of-icon-defun)))
  279.       (while (< (point) indent-point)
  280.     (setq parse-start (point))
  281.     (setq state (parse-partial-sexp (point) indent-point 0))
  282.     (setq containing-sexp (car (cdr state))))
  283.       (cond ((or (nth 3 state) (nth 4 state))
  284.          ;; return nil or t if should not change this line
  285.          (nth 4 state))
  286.         ((and containing-sexp
  287.           (/= (char-after containing-sexp) ?{))
  288.          ;; line is expression, not statement:
  289.          ;; indent to just after the surrounding open.
  290.          (goto-char (1+ containing-sexp))
  291.          (current-column))
  292.         (t
  293.           (if toplevel
  294.           ;; Outside any procedures.
  295.           (progn (icon-backward-to-noncomment (point-min))
  296.              (if (icon-is-continuation-line)
  297.                  icon-continued-statement-offset 0))
  298.         ;; Statement level.
  299.         (if (null containing-sexp)
  300.             (progn (beginning-of-icon-defun)
  301.                (setq containing-sexp (point))))
  302.         (goto-char indent-point)
  303.         ;; Is it a continuation or a new statement?
  304.         ;; Find previous non-comment character.
  305.         (icon-backward-to-noncomment containing-sexp)
  306.         ;; Now we get the answer.
  307.         (if (icon-is-continuation-line)
  308.             ;; This line is continuation of preceding line's statement;
  309.             ;; indent  icon-continued-statement-offset  more than the
  310.             ;; first line of the statement.
  311.             (progn
  312.               (icon-backward-to-start-of-continued-exp containing-sexp)
  313.               (+ icon-continued-statement-offset (current-column)
  314.              (if (save-excursion (goto-char indent-point)
  315.                          (skip-chars-forward " \t")
  316.                          (eq (following-char) ?{))
  317.                  icon-continued-brace-offset 0)))
  318.           ;; This line starts a new statement.
  319.           ;; Position following last unclosed open.
  320.           (goto-char containing-sexp)
  321.           ;; Is line first statement after an open-brace?
  322.           (or
  323.             ;; If no, find that first statement and indent like it.
  324.             (save-excursion
  325.               (if (looking-at "procedure\\s ")
  326.               (forward-sexp 3)
  327.             (forward-char 1))
  328.               (while (progn (skip-chars-forward " \t\n")
  329.                     (looking-at "#"))
  330.             ;; Skip over comments following openbrace.
  331.             (forward-line 1))
  332.               ;; The first following code counts
  333.               ;; if it is before the line we want to indent.
  334.               (and (< (point) indent-point)
  335.                (current-column)))
  336.             ;; If no previous statement,
  337.             ;; indent it relative to line brace is on.
  338.             ;; For open brace in column zero, don't let statement
  339.             ;; start there too.  If icon-indent-level is zero,
  340.             ;; use icon-brace-offset + icon-continued-statement-offset
  341.             ;; instead.
  342.             ;; For open-braces not the first thing in a line,
  343.             ;; add in icon-brace-imaginary-offset.
  344.             (+ (if (and (bolp) (zerop icon-indent-level))
  345.                (+ icon-brace-offset
  346.                   icon-continued-statement-offset)
  347.              icon-indent-level)
  348.                ;; Move back over whitespace before the openbrace.
  349.                ;; If openbrace is not first nonwhite thing on the line,
  350.                ;; add the icon-brace-imaginary-offset.
  351.                (progn (skip-chars-backward " \t")
  352.                   (if (bolp) 0 icon-brace-imaginary-offset))
  353.                ;; Get initial indentation of the line we are on.
  354.                (current-indentation))))))))))
  355.  
  356. ;; List of words to check for as the last thing on a line.
  357. ;; If cdr is t, next line is a continuation of the same statement,
  358. ;; if cdr is nil, next line starts a new (possibly indented) statement.
  359.  
  360. (defconst icon-resword-alist
  361.   '(("by" . t) ("case" . t) ("create") ("do") ("dynamic" . t) ("else")
  362.     ("every" . t) ("if" . t) ("global" . t) ("initial" . t)
  363.     ("link" . t) ("local" . t) ("of") ("record" . t) ("repeat" . t)
  364.     ("static" . t) ("then") ("to" . t) ("until" . t) ("while" . t)))
  365.  
  366. (defun icon-is-continuation-line ()
  367.   (let* ((ch (preceding-char))
  368.      (ch-syntax (char-syntax ch)))
  369.     (if (eq ch-syntax ?w)
  370.     (assoc (buffer-substring
  371.         (progn (forward-word -1) (point))
  372.         (progn (forward-word 1) (point)))
  373.            icon-resword-alist)
  374.       (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
  375.  
  376. (defun icon-backward-to-noncomment (lim)
  377.   (let (opoint stop)
  378.     (while (not stop)
  379.       (skip-chars-backward " \t\n\f" lim)
  380.       (setq opoint (point))
  381.       (beginning-of-line)
  382.       (if (and (nth 5 (parse-partial-sexp (point) opoint))
  383.            (< lim (point)))
  384.       (search-backward "#")
  385.     (setq stop t)))))
  386.  
  387. (defun icon-backward-to-start-of-continued-exp (lim)
  388.   (if (memq (preceding-char) '(?\) ?\]))
  389.       (forward-sexp -1))
  390.   (beginning-of-line)
  391.   (skip-chars-forward " \t")
  392.   (cond
  393.    ((<= (point) lim) (goto-char (1+ lim)))
  394.    ((not (icon-is-continued-line)) 0)
  395.    ((and (eq (char-syntax (following-char)) ?w)
  396.      (cdr
  397.       (assoc (buffer-substring (point)
  398.                    (save-excursion (forward-word 1) (point)))
  399.          icon-resword-alist))) 0)
  400.    (t (end-of-line 0) (icon-backward-to-start-of-continued-exp lim))))
  401.  
  402. (defun icon-is-continued-line ()
  403.   (save-excursion
  404.     (end-of-line 0)
  405.     (icon-is-continuation-line)))
  406.  
  407. (defun icon-backward-to-start-of-if (&optional limit)
  408.   "Move to the start of the last ``unbalanced'' if."
  409.   (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
  410.   (let ((if-level 1)
  411.     (case-fold-search nil))
  412.     (while (not (zerop if-level))
  413.       (backward-sexp 1)
  414.       (cond ((looking-at "else\\b")
  415.          (setq if-level (1+ if-level)))
  416.         ((looking-at "if\\b")
  417.          (setq if-level (1- if-level)))
  418.         ((< (point) limit)
  419.          (setq if-level 0)
  420.          (goto-char limit))))))
  421.  
  422. (defun mark-icon-function ()
  423.   "Put mark at end of Icon function, point at beginning."
  424.   (interactive)
  425.   (push-mark (point))
  426.   (end-of-icon-defun)
  427.   (push-mark (point))
  428.   (beginning-of-line 0)
  429.   (beginning-of-icon-defun))
  430.  
  431. (defun beginning-of-icon-defun ()
  432.   "Go to the start of the enclosing procedure; return t if at top level."
  433.   (interactive)
  434.   (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
  435.       (looking-at "e")
  436.     t))
  437.  
  438. (defun end-of-icon-defun ()
  439.   (interactive)
  440.   (if (not (bobp)) (forward-char -1))
  441.   (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
  442.   (forward-word -1)
  443.   (forward-line 1))
  444.  
  445. (defun indent-icon-exp ()
  446.   "Indent each line of the Icon grouping following point."
  447.   (interactive)
  448.   (let ((indent-stack (list nil))
  449.     (contain-stack (list (point)))
  450.     (case-fold-search nil)
  451.     restart outer-loop-done inner-loop-done state ostate
  452.     this-indent last-sexp
  453.     at-else at-brace at-do
  454.     (opoint (point))
  455.     (next-depth 0))
  456.     (save-excursion
  457.       (forward-sexp 1))
  458.     (save-excursion
  459.       (setq outer-loop-done nil)
  460.       (while (and (not (eobp)) (not outer-loop-done))
  461.     (setq last-depth next-depth)
  462.     ;; Compute how depth changes over this line
  463.     ;; plus enough other lines to get to one that
  464.     ;; does not end inside a comment or string.
  465.     ;; Meanwhile, do appropriate indentation on comment lines.
  466.     (setq innerloop-done nil)
  467.     (while (and (not innerloop-done)
  468.             (not (and (eobp) (setq outer-loop-done t))))
  469.       (setq ostate state)
  470.       (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
  471.                       nil nil state))
  472.       (setq next-depth (car state))
  473.       (if (and (car (cdr (cdr state)))
  474.            (>= (car (cdr (cdr state))) 0))
  475.           (setq last-sexp (car (cdr (cdr state)))))
  476.       (if (or (nth 4 ostate))
  477.           (icon-indent-line))
  478.       (if (or (nth 3 state))
  479.           (forward-line 1)
  480.         (setq innerloop-done t)))
  481.     (if (<= next-depth 0)
  482.         (setq outer-loop-done t))
  483.     (if outer-loop-done
  484.         nil
  485.       (if (/= last-depth next-depth)
  486.           (setq last-sexp nil))
  487.       (while (> last-depth next-depth)
  488.         (setq indent-stack (cdr indent-stack)
  489.           contain-stack (cdr contain-stack)
  490.           last-depth (1- last-depth)))
  491.       (while (< last-depth next-depth)
  492.         (setq indent-stack (cons nil indent-stack)
  493.           contain-stack (cons nil contain-stack)
  494.           last-depth (1+ last-depth)))
  495.       (if (null (car contain-stack))
  496.           (setcar contain-stack (or (car (cdr state))
  497.                     (save-excursion (forward-sexp -1)
  498.                             (point)))))
  499.       (forward-line 1)
  500.       (skip-chars-forward " \t")
  501.       (if (eolp)
  502.           nil
  503.         (if (and (car indent-stack)
  504.              (>= (car indent-stack) 0))
  505.         ;; Line is on an existing nesting level.
  506.         ;; Lines inside parens are handled specially.
  507.         (if (/= (char-after (car contain-stack)) ?{)
  508.             (setq this-indent (car indent-stack))
  509.           ;; Line is at statement level.
  510.           ;; Is it a new statement?  Is it an else?
  511.           ;; Find last non-comment character before this line
  512.           (save-excursion
  513.             (setq at-else (looking-at "else\\W"))
  514.             (setq at-brace (= (following-char) ?{))
  515.             (icon-backward-to-noncomment opoint)
  516.             (if (icon-is-continuation-line)
  517.             ;; Preceding line did not end in comma or semi;
  518.             ;; indent this line  icon-continued-statement-offset
  519.             ;; more than previous.
  520.             (progn
  521.               (icon-backward-to-start-of-continued-exp (car contain-stack))
  522.               (setq this-indent
  523.                 (+ icon-continued-statement-offset (current-column)
  524.                    (if at-brace icon-continued-brace-offset 0))))
  525.               ;; Preceding line ended in comma or semi;
  526.               ;; use the standard indent for this level.
  527.               (if at-else
  528.               (progn (icon-backward-to-start-of-if opoint)
  529.                  (setq this-indent (current-indentation)))
  530.             (setq this-indent (car indent-stack))))))
  531.           ;; Just started a new nesting level.
  532.           ;; Compute the standard indent for this level.
  533.           (let ((val (calculate-icon-indent
  534.                (if (car indent-stack)
  535.                    (- (car indent-stack))))))
  536.         (setcar indent-stack
  537.             (setq this-indent val))))
  538.         ;; Adjust line indentation according to its contents
  539.         (if (or (= (following-char) ?})
  540.             (looking-at "end\\b"))
  541.         (setq this-indent (- this-indent icon-indent-level)))
  542.         (if (= (following-char) ?{)
  543.         (setq this-indent (+ this-indent icon-brace-offset)))
  544.         ;; Put chosen indentation into effect.
  545.         (or (= (current-column) this-indent)
  546.         (progn
  547.           (delete-region (point) (progn (beginning-of-line) (point)))
  548.           (indent-to this-indent)))
  549.         ;; Indent any comment following the text.
  550.         (or (looking-at comment-start-skip)
  551.         (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
  552.             (progn (indent-for-comment) (beginning-of-line))))))))))
  553.  
  554.